import { createRouter, createWebHashHistory } from 'vue-router';
import routes from './list';

import type { Router } from 'vue-router';

const router: Router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, _from, next) => {
    if (to.path === '/' || to.path === '/login') {
        next();
    } else {
        if (MyModule.storage.getItem('token', '')) {
            next();
        } else {
            next('/login');
        }
    }
});

export default router;
